package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hyh
 * @version 1.0
 */
@Api(tags = "购物车接口开发")
@Slf4j
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public Result addShopCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车数据为{}",shoppingCartDTO);
        shoppingCartService.addShopCart(shoppingCartDTO);
        return Result.success();
    }
    @GetMapping("/list")
    public Result<List> ShopCartView(){
        log.info("查看购物车");
        List<ShoppingCart> list = shoppingCartService.shopView();
        return Result.success(list);
    }
    @DeleteMapping("/clean")
    public Result DeleteALL(){
        log.info("清空购物车");
        shoppingCartService.Clean();
        return Result.success();
    }
    @PostMapping("/sub")
    public Result DeleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除某一个菜品{}",shoppingCartDTO);
        shoppingCartService.deleteOne(shoppingCartDTO);
        return Result.success();
    }


}
